package com.tansun.easycare.rule.executionblock.entity;

public class BPMNTask {
	
	private String id;
	
	private String modelFunction;

	private String code;
	
	private String modelVersion;
	
	private String name;
	
	private String projectCode;
	
	private String condition;
	
	private String sortLevel;
	
	private String xml;

	public void buildByModelFunction(String id,String modelFunction,String space,String wrap) {
		this.id = id;
		this.modelFunction = modelFunction;
    	StringBuffer content = new StringBuffer();
		content.append(space + "<scriptTask id=\"" + id + "\" name=\"Script"+id+"\" scriptFormat=\"http://www.java.com/java\">"+wrap);
        content.append(space + "	<script>" + modelFunction + "(dataMap,metaMap);"+ "\r\n" + "</script>"+wrap );//脚本执行以换行符结束
        content.append(space + "</scriptTask>"+wrap);
        xml = content.toString();
	}
	
	public void buildByCode(String id,String code,String space,String wrap) {
		this.id = id;
		this.code = code;
    	StringBuffer content = new StringBuffer();
		content.append(space + "<scriptTask id=\"" + id + "\" name=\"Script"+id+"\" scriptFormat=\"http://www.java.com/java\">"+wrap);
        content.append(space + "	<script>" + code +"\r\n" + "</script>"+wrap );//脚本执行以换行符结束
        content.append(space + "</scriptTask>"+wrap);
        xml = content.toString();
	}
	
	public void buildEndEvent(String id,String space,String wrap) {
		this.id = id;
		xml = space + "<endEvent id=\""+id+"\" name=\"\"/>" + wrap;
	}
	
	public void buildByRuleFlowOrExecutionBlock(String id,String name,String modelVersion,String space,String wrap) {
		this.id = id;
		this.name = name;
		this.modelVersion = modelVersion;
    	StringBuffer content = new StringBuffer();
    	content.append(space + "<callActivity id=\"" + id + "\" name=\"" + name + "\" calledElement=\"" + modelVersion + "\">" + wrap);
    	content.append(space + "	<ioSpecification>" + wrap);
    	content.append(space + "		<inputSet>" + wrap);
    	content.append(space + "		</inputSet>" + wrap);
    	content.append(space + "		<outputSet>" + wrap);
    	content.append(space + "		</outputSet>" + wrap);
    	content.append(space + "	</ioSpecification>" + wrap);
    	content.append(space + "</callActivity>" + wrap);
        xml = content.toString();
	}
	
	public void buildByDataMining(String id,String modelCode,String name,String modelVersion,String projectCode,String space,String wrap) {
		this.id = id;
		this.name = name;
		this.modelVersion = modelVersion;
		this.projectCode = projectCode;
    	StringBuffer content = new StringBuffer();
    	String codeSc = "droolsRuleLog.addLogs(\""+modelCode+"\",\"datamining\", \""+modelVersion+ "\", \""+modelVersion+ "\", \""+modelVersion+ "\", 1);\r\n";
    	codeSc += "ruleHelper.evaluatePmml(\""+modelVersion+"\",\""+projectCode+"\",dataMap);";
    	content.append(space + "<scriptTask id=\"" + id + "\" name=\"Script\" scriptFormat=\"http://www.java.com/java\">" + wrap);
    	content.append(space + "	<script>" + codeSc + "\r\n" + "</script>" + wrap);//脚本执行以换行符结束
        content.append(space + "</scriptTask>" + wrap);
        xml = content.toString();
	}
	
	public void buildOther(String id,String name,String modelVersion,String space,String wrap) {
		this.id = id;
		this.name = name;
		this.modelVersion = modelVersion;
    	StringBuffer content = new StringBuffer();
    	content.append(space + "<businessRuleTask id=\"" + id + "\" name=\"" + name + "\" g:ruleFlowGroup=\"" + modelVersion + "\">" + wrap);
        content.append(space + "	<ioSpecification>" + wrap);
        content.append(space + "		<inputSet>" + wrap);
        content.append(space + "		</inputSet>" + wrap);
        content.append(space + "		<outputSet>" + wrap);
        content.append(space + "		</outputSet>" + wrap);
        content.append(space + "	</ioSpecification>" + wrap);
        content.append(space + "</businessRuleTask>" + wrap);
        xml = content.toString();
	}

	public void buildGateway(String id,String type,String space,String wrap) {
		if("IGW".equals(type)) {
			this.id = "IGW"+id;
			this.name = "branch"+id;
       		xml = space + "<inclusiveGateway id=\""+this.id+"\" name=\"branch"+this.name+"\" gatewayDirection=\"Diverging\"/>" + wrap;
		}else if("EGW".equals(type)) {
			this.id = "EGW"+id;
			this.name = "merge"+id;
        	xml = space + "<exclusiveGateway id=\""+this.id+"\" name=\""+this.name+"\" gatewayDirection=\"Converging\"/>" + wrap;
		}
	}
	
	public BPMNShape toBPMNShape(int x,int y) {
		return new BPMNShape(id,x, y);
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getModelFunction() {
		return modelFunction;
	}

	public void setModelFunction(String modelFunction) {
		this.modelFunction = modelFunction;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getModelVersion() {
		return modelVersion;
	}

	public void setModelVersion(String modelVersion) {
		this.modelVersion = modelVersion;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProjectCode() {
		return projectCode;
	}

	public void setProjectCode(String projectCode) {
		this.projectCode = projectCode;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public String getSortLevel() {
		return sortLevel;
	}

	public void setSortLevel(String sortLevel) {
		this.sortLevel = sortLevel;
	}

	public String getXml() {
		return xml;
	}

	public void setXml(String xml) {
		this.xml = xml;
	}
	
	
}
